package edu.yctc.manage.service.impl;

import edu.yctc.manage.dao.CourseDAO;
import edu.yctc.manage.entity.CourseDO;
import edu.yctc.manage.entity.PageDO;
import edu.yctc.manage.service.CourseService;
import edu.yctc.manage.utils.PageQuery;
import edu.yctc.manage.utils.VOUtil;
import edu.yctc.manage.vo.CourseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * @ClassName CourseServiceImpl
 * @Description TODO
 * @Author zyj
 * @Date 2021/3/31 14:56
 * @Version 1.0
 **/
@Service
public class CourseServiceImpl implements CourseService {

    @Resource
    private CourseDAO courseDAO;

    @Autowired
    private VOUtil voUtil;

    @Override public PageDO getVOList(PageQuery pageQuery) {
        List<CourseVO> courseVOS = voUtil.CourseDOs2VOs(courseDAO.selectList(pageQuery));
        int total = courseDAO.getTotal();
        return new PageDO(total, pageQuery.getLimit(), pageQuery.getPage(), courseVOS);
    }

    @Override public int save(CourseDO courseDO) {
        return courseDAO.insert(courseDO);
    }

    @Override public int update(CourseDO courseDO) {
        return courseDAO.update(courseDO);
    }

    @Override public int delete(Long[] ids) {
        return courseDAO.deleteBatchIds(Arrays.asList(ids));
    }
}
    